package com.pgeneral.user.management.controller;

import com.pgeneral.user.management.config.ResultBean;
import com.pgeneral.user.management.entity.SopRole;
import com.pgeneral.user.management.service.impl.SopRoleServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 角色的怎删改查接口
 */
@Slf4j
@RestController
@RequestMapping("/soprole")
public class SopRoleController {

    @Autowired
    private SopRoleServiceImpl soproleService;

    /**
     * 添加角色信息
     *
     * @param sopRoles
     * @return
     */
    @RequestMapping(value = "/saveInfo", method = RequestMethod.POST)
    public ResultBean insertSopRoleTable(@RequestBody List<SopRole> sopRoles) {
        log.info("调用角色save方法，方法参数为：{}",sopRoles);
        int result = soproleService.insert(sopRoles);
        return ResultBean.InsertSuccessResult(result);

    }

    /**
     * 角色查询
     *
     * @param sopRole
     * @return
     */
    @RequestMapping(value = "/getInfo", method = RequestMethod.POST)
    public ResultBean getSopRoleTable(@RequestBody SopRole sopRole) {
        log.info("调用角色get方法，方法参数为：{}",sopRole);
        List<SopRole> sopRoleTable = soproleService.getSopRoleTable(sopRole);
        return ResultBean.Success(sopRoleTable);

    }

    /**
     * 角色更新
     *
     * @param sopRoles
     * @return
     */
    @RequestMapping(value = "/updateInfo", method = RequestMethod.POST)
    public ResultBean updateSopRoleTable(@RequestBody List<SopRole> sopRoles) {
        log.info("调用角色update方法，方法参数为：{}",sopRoles);
        int result = soproleService.updateSopRoleTable(sopRoles);
        return ResultBean.InsertSuccessResult(result);

    }

    /**
     * 角色删除
     *
     * @param ids
     * @return
     */
    @RequestMapping(value = "/deleteInfo", method = RequestMethod.POST)
    public ResultBean deleteSopRoleTable(@RequestBody List<String> ids) {
        System.out.println("角色delete");
        log.info("调用角色delete方法，方法参数为：{}",ids);
        int result = soproleService.updateIsDeletefromSopRoleTable(ids);
        return ResultBean.InsertSuccessResult(result);
    }
}
